#include "statusmonitoringcontroller.h"

StatusMonitoringController::StatusMonitoringController(QObject *parent)
    : QObject{parent}
{
    statusMonitoringView = new StatusMonitoringView();
    setPropulsionStatus(DisplayPropulsionStatus::STATE_B);
    setTrainRegistrationStatus(true);
    setDoorEnableStatus(DoorEnableStatus::LEFT_STATE);
    setPsdStatus(PsdStatus::OPENED_PSD);
    setDoorStatus(DoorStatus::OPENED_DOOR);
    setHoldTrain(true);
    setTrainStoppingWindowType(TrainStoppingWindowType::RED_WindowType);
    setSkipStation(true);
    setTrainEmergencyBrake(true);
    setDoorModeType(DoorModeType::DoorMode_AA);
}

StatusMonitoringController::~StatusMonitoringController()
{

}

void StatusMonitoringController::show(QVBoxLayout *vLayout, int stretch)
{
    vLayout->addWidget(statusMonitoringView,stretch);
}

void StatusMonitoringController::setPropulsionStatus(DisplayPropulsionStatus state)
{
    QString str = ":images/";
    switch (state) {
    case DisplayPropulsionStatus::STATE_M:
        str = str + "prop_motoring.png";
        break;
    case DisplayPropulsionStatus::STATE_B:
        str = str + "prop_braking.png";
        break;
    case DisplayPropulsionStatus::STATE_C:
        str = str + "prop_coasting.png";
        break;
    case DisplayPropulsionStatus::STATE_S:
        str = str + "prop_stationary.png";
        break;
    case DisplayPropulsionStatus::STATE_N:
        break;
    default:
        break;
    }
    statusMonitoringView->label[0]->setPixmap(QPixmap(str));
}

void StatusMonitoringController::setTrainRegistrationStatus(bool state)
{
    if(state){
        statusMonitoringView->label[1]->setPixmap(QPixmap(":images/cbtc_on.png"));
    }
}

void StatusMonitoringController::setDoorEnableStatus(DoorEnableStatus state)
{
    QString str = ":images/";
    switch (state) {
    case DoorEnableStatus::BLANK_STARTE:
        str = str + "door_locked.png";
        break;
    case DoorEnableStatus::ARROWS:
        str = str + "door_ena_both.png";
        break;
    case DoorEnableStatus::LEFT_STATE:
        str = str + "door_ena_left.png";
        break;
    case DoorEnableStatus::RIGHT_STATE:
        str = str + "door_ena_right.png";
        break;
    default:
        break;
    }
    statusMonitoringView->label[2]->setPixmap(QPixmap(str));
}

void StatusMonitoringController::setPsdStatus(PsdStatus state)
{
    QString str = ":images/";
    switch (state) {
    case PsdStatus::CLOSED_PSD:
        str = str + "psd_close.png";
        break;
    case PsdStatus::OPENED_PSD:
        str = str + "psd_open_both.png";
        break;
    case PsdStatus::LEFT_PSD:
        str = str + "psd_open_left.png";
        break;
    case PsdStatus::RIGHT_PSD:
        str = str + "psd_open_right.png";
        break;
    default:
        break;
    }
    statusMonitoringView->label[3]->setPixmap(QPixmap(str));
}

void StatusMonitoringController::setDoorStatus(DoorStatus state)
{
    QString str = ":images/";
    switch (state) {
    case DoorStatus::CLOSED_DOOR:
        str = str + "door_close.png";
        break;
    case DoorStatus::OPENED_DOOR:
        str = str + "door_open_both.png";
        break;
    case DoorStatus::LEFT_DOOR:
        str = str + "door_open_left.png";
        break;
    case DoorStatus::RIGHT_DOOR:
        str = str + "door_open_right.png";
        break;
    default:
        break;
    }
    statusMonitoringView->label[4]->setPixmap(QPixmap(str));
}

void StatusMonitoringController::setHoldTrain(bool state)
{
    if(state){
        statusMonitoringView->label[5]->setPixmap(QPixmap(":images/hold_train.png"));
    }
    //    白色“保持列车”()指示灯表示从OCC发出保持列车命令
    //        空白指示表示未从OCC应用保持列车命令
}

void StatusMonitoringController::setTrainStoppingWindowType(TrainStoppingWindowType type)
{
    QString str = ":images/";
    switch (type) {
    case TrainStoppingWindowType::GREEN_WindowType:
        str = str + "window_stop_in.png";
        break;
    case TrainStoppingWindowType::RED_WindowType:
        str = str + "window_stop_out.png";
        break;
    case TrainStoppingWindowType::BLANK_WindowType:
        break;
    default:
        break;
    }
    statusMonitoringView->label[6]->setPixmap(QPixmap(str));
}

void StatusMonitoringController::setSkipStation(bool state)
{
    if(state){
        statusMonitoringView->label[7]->setPixmap(QPixmap(":images/skip_station.png"));
    }
}

void StatusMonitoringController::setTrainEmergencyBrake(bool state)
{
    if(state){
        statusMonitoringView->label[8]->setPixmap(QPixmap(":images/eb_vatc.png"));
    }else {
        statusMonitoringView->label[8]->setPixmap(QPixmap(":images/eb_reset.png"));
    }

}

void StatusMonitoringController::setDoorModeType(DoorModeType mode)
{
    QString str = ":images/";
    switch (mode) {
    case DoorModeType::DoorMode:
        str = str + "window_stop_in.png";
        break;
    case DoorModeType::DoorMode_AA:
        str = str + "door_modeAA.png";
        break;
    case DoorModeType::DoorMode_AM:
        str = str + "door_modeAM.png";
        break;
    case DoorModeType::DoorMode_MM:
        str = str + "door_modeMM.png";
        break;
    default:
        break;
    }
    statusMonitoringView->label[9]->setPixmap(QPixmap(str));
}


























